package main

import "fmt"

func main() {
	var nums []int
	nums = []int{0, 1, 2, 4, 5, 7}
	v := summaryRanges(nums)
	fmt.Println(v)
}

//228. 汇总区间

func summaryRanges(nums []int) []string {
	n := len(nums)
	res := []string{}

	i := 0
	for i < n {
		j := i + 1
		for j < n && nums[j] == (nums[j-1]+1) {
			j++
		}
		j--
		if i == j {
			res = append(res, fmt.Sprintf("%d", nums[i]))
		} else {
			res = append(res, fmt.Sprintf("%d->%d", nums[i], nums[j]))
		}
		i = j + 1
	}
	return res
}
